You also don't check the result of your malloc, you assume it succeeds and continue on... malloc returns a NULL pointer on failure.
Printable View
You also don't check the result of your malloc, you assume it succeeds and continue on... malloc returns a NULL pointer on failure.
try strdup();